$(function () {
    var leavingStudent_datagrid = $('#leavingStudent_datagrid');
    var combobox_role = $("#combobox_role");
    $('#leavingStudent_datagrid').datagrid({
        url: '/leavingStudent/list',
        fit: true,
        pagination: true,
        rownumbers: true,
        border: false,
        singleSelect: true,
        fitColumns: true,
        toolbar: '#leavingStudent_datagrid_button',
        columns: [[
            {field: 'id', title: 'Id', width: 100},
            {field: 'name', title: '姓名', width: 100},
            {field: 'tel', title: '电话', width: 100},
            {field: 'classGrade', title: '班级', width: 100},
            {field: 'leavingStage', title: '流失阶段', width: 100,formatter:formatterleavingStage},
            {field: 'leavingTime', title: '流失时间', width: 100,formatter:formatDate},
            {field: 'backMoneyAmount', title: '退款', width: 100},
            {field: 'marketer', title: '营销人员', width: 100},
            {field: 'operator', title: '经办人', width: 100},
            {field: 'auditStatus', title: '审核', width: 100,formatter:formatterauditStatus},
        ]]
    });

    var cmdObj = {
        //流失学院审核操作
        aduitLeavingStudent: function () {
           console.log("9999999999999999999999999");
           var selectedRow = leavingStudent_datagrid.datagrid("getSelected");
    if (!selectedRow) {
        $.messager.alert('警告', '请选择你要审核的一行', 'warning');
        return;
    } else {
        $.messager.confirm('温馨提示', '你确定要审核通过吗？', function (yes) {
            console.log("能进来!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1")
           if (yes) {
                $.post("/leavingStudent/aduit", {id:selectedRow.id,tel: selectedRow.tel}, function (data) {
                    if (data.success) {
                        $.messager.alert('提示', "审核通过!", function () {
                            leavingStudent_datagrid.datagrid("reload");
                        })
                    } else {
                        $.messager.alert('提示', data.msg, 'error');
                    }
                })
            }
        });
    }
},
    };
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    });
});


function formatterleavingStage(value,row,index) {
    if (value == 1) {
        return "大神班阶段";
    } else {
        return "基础班阶段";
    }
}

function formatterauditStatus(value,row,index) {
    if (value == 0) {
        return "<span style='color:green'>"+"待审核"+"</span>";
    } else {
        return "<span style='color:green'>"+"已经审核"+"</span>";

    }
}
function formatDate(value,row,index){
    var unixTimestamp = new Date(value);
    return unixTimestamp.toLocaleString();
}
